/**
 *  SOsim: Simulator for Operating Systems Education
 *
 * 		SOsim is a simulator with visual facilities to serve as an effective 
 *  support tool for the better teaching and learning of the concepts and techniques 
 *  in modern operating systems, serving as a way to render the whole process more 
 *  efficient.
 *  Copyright (C) 2011  Luiz Paulo Maia
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package br.org.sosim.controller;

public class TEstatisticas {
	 
	        public void TEstatisticas()
	        {
	            InitializeComponent();
	        }

	        public string MemLivre()
	        {
	            string result;
	            result = FormatFloat("#0", (f_Console.Units.f_Console.MemoReal.MemoriaLivre() * u_Consts.Units.u_Consts.PAGE_SIZE) / (u_Consts.Units.u_Consts.MAX_FRAME * u_Consts.Units.u_Consts.PAGE_SIZE) * 100) + '%';
	            return result;
	        }

	        public void FormCreate(System.Object Sender, System.EventArgs _e1)
	        {
	            f_Console.Units.f_Console.Form1.Estatsticas1.Checked = false;
	            StaticText1.Text = DateTime.Now.ToString();
	            Units.f_Estatistica.Estatisticas.Text = u_Consts.Units.u_Consts.msg9005;
	            u_language.Units.u_language.GetLanguageObject().LoadLanguageCaptions("STAT", this);
	            StaticText6.Text = "0,00";
	            StaticText10.Text = '0';
	            StaticText11.Text = '0';
	            StaticText13.Text = '0';
	            StaticText16.Text = '0';
	            Timer2.Interval = 5000;
	            

	        }

	        public void Timer1Timer(System.Object Sender, System.EventArgs _e1)
	        {
	            public int Exec;
	            public int Prontos;
	            public int Espera;
	            public int TempoTotalProcessosPronto;
	            public int NumProcessosPronto;
	            public int TPF;
	            public int THPF;
	            public int TSPF;
	            StaticText2.Text = (f_Console.Units.f_Console.Clock.TempoTotalSim).ToString();
	            StaticText3.Text = (f_Console.Units.f_Console.Kernel.ListaProcessos.Count).ToString();
	            StaticText15.Text = (f_Console.Units.f_Console.NumProcessosEscalonados).ToString();
	            StaticText4.Text = FormatFloat("#,##0.00", f_Console.Units.f_Console.NumProcessosEscalonados / f_Console.Units.f_Console.Clock.TempoTotalSim);
	            StaticText5.Text = (f_Console.Units.f_Console.CPU.TempoTotalCPU).ToString();
	            f_Console.Units.f_Console.Kernel.NumeroProcessosPorEstado(ref Exec, ref Prontos, ref Espera);
	            StaticText7.Text = (Prontos).ToString();
	            StaticText8.Text = (Exec).ToString();
	            StaticText9.Text = (Espera).ToString();
	            if ((f_Console.Units.f_Console.NumProcessosFinalizados > 0))
	            {
	                
	                StaticText10.Text = FormatFloat("#,##0.00", f_Console.Units.f_Console.Clock.TempoTotalSim / f_Console.Units.f_Console.NumProcessosFinalizados);
	            }
	            else
	            {
	                StaticText10.Text = ' ';
	            }
	            f_Console.Units.f_Console.Kernel.VerificaEstadoPronto(ref TempoTotalProcessosPronto, ref NumProcessosPronto);
	            
	            StaticText12.Text = FormatFloat("#,##0.00", RetornaSeg(TempoTotalProcessosPronto));
	            if ((NumProcessosPronto > 0))
	            {
	                
	                StaticText13.Text = FormatFloat("#,##0.00", TempoTotalProcessosPronto / NumProcessosPronto);
	            }
	            else if ((f_Console.Units.f_Console.Kernel.ListaProcessos.Count == 0))
	            {
	                StaticText13.Text = ' ';
	            }
	            if ((f_Console.Units.f_Console.NumProcessosEscalonados > 0))
	            {
	                
	                StaticText11.Text = FormatFloat("#,##0.00", f_Console.Units.f_Console.TempoAcumuladoProcessosPronto / f_Console.Units.f_Console.NumProcessosEscalonados);
	            }
	            else
	            {
	                StaticText11.Text = ' ';
	            }
	            f_Console.Units.f_Console.MemoReal.TotalPageFaults(ref THPF, ref TSPF);
	            TPF = THPF + TSPF;
	            StaticText14.Text = (TPF).ToString();
	            if ((TPF > 0))
	            {
	               
	                StaticText16.Text = FormatFloat("#,##0.00", TPF / f_Console.Units.f_Console.Clock.TempoTotalSim);
	            }
	            StaticText20.Text = (THPF).ToString();
	            StaticText21.Text = (TSPF).ToString();
	            StaticText17.Text = (u_Consts.Units.u_Consts.MAX_FRAME * u_Consts.Units.u_Consts.PAGE_SIZE).ToString();
	            StaticText18.Text = ((u_Consts.Units.u_Consts.MAX_FRAME * u_Consts.Units.u_Consts.PAGE_SIZE) - f_Console.Units.f_Console.MemoReal.MemoriaLivre() * u_Consts.Units.u_Consts.PAGE_SIZE).ToString();
	            StaticText19.Text = Units.f_Estatistica.Estatisticas.MemLivre();
	        }

	        private int RetornaSeg(DateTime D)
	        {
	            int result;
	            result = Convert.ToInt64((double)D * 86400);
	            return result;
	        }

	       
	        public void FormClose(System.Object Sender, System.EventArgs _e1)
	        {
	            f_Console.Units.f_Console.Form1.Estatsticas1.Checked = false;
	        }

	        public void Timer2Timer(System.Object Sender, System.EventArgs _e1)
	        {
	            if ((f_Console.Units.f_Console.Clock.TempoEstatistica != 0))
	            {
	                
	                StaticText6.Text = FormatFloat("#,##0.00", (f_Console.Units.f_Console.CPU.TempoEstatCPU / f_Console.Units.f_Console.Clock.TempoEstatistica) * 100);
	            }
	            f_Console.Units.f_Console.CPU.TempoEstatCPU = 0;
	            f_Console.Units.f_Console.Clock.TempoEstatistica = 0;
	        }

	    } 

	}


